


class GelismisHesap {

	private double miktar = 50; 

	public  double paraYatir(double m) {
		this.miktar += m ; 
		return miktar;
	}

	public  void paraCek(double m) {
		if (this.miktar < 0) {
			System.out.println("Bakiye yetersiz " + this.miktar);
			return;	// metodu terk et
		}
		this.miktar -= m ; 
	}

	public double miktariOgren() {
		return miktar;
	}
}



class GelismisBankaCalisaniBir extends Thread {

	GelismisHesap gh ; 

	public GelismisBankaCalisaniBir( String isim, GelismisHesap gh) {
		super(isim);
		this.gh = gh ;
	}

	public void run() {

		try {

			synchronized(gh) {

				double miktar = gh.miktariOgren();
				double ilkMiktar = miktar;
				gh.paraYatir(100);
				sleep(1);
				gh.paraYatir(100);
				sleep(1);
				gh.paraCek(150);
				miktar = gh.miktariOgren();
				// islem sonunda elde etmesi gereken
				System.out.println(currentThread().getName()+"-->"
								   +ilkMiktar+" + 100 + 100 - 150 =" + miktar );
			}


		} catch (InterruptedException iEx) {
		}
	}
}

class GelismisBankaCalisaniIki extends Thread {

	GelismisHesap gh ; 

	public GelismisBankaCalisaniIki( String isim, GelismisHesap gh) {
		super(isim);
		this.gh = gh ;

	}

	public void run() {

		try {

			synchronized(gh) {
				double miktar = gh.miktariOgren();
				double ilkMiktar = miktar;
				gh.paraYatir(200);
				sleep(1);
				gh.paraCek(50);
				sleep(2);
				gh.paraYatir(100);
				miktar = gh.miktariOgren();
				// islem sonunda elde etmesi gereken
				System.out.println(currentThread().getName()+"-->"
								   +ilkMiktar+" + 200 - 50 + 100 =" + miktar );
			}

		} catch (InterruptedException iEx) {
		}
	}
}

public class GelismisBanka extends Thread {

	public static void main(String args[]) throws Exception {

		GelismisHesap gh = new GelismisHesap();

		GelismisBankaCalisaniBir gbc1 = 
		        new GelismisBankaCalisaniBir("GelismisBankaCalisaniBir", gh);
		
		GelismisBankaCalisaniIki gbc2 = 
		        new GelismisBankaCalisaniIki("GelismisBankaCalisaniIki", gh);

		gbc1.start();
		gbc2.start();


	}
}

